﻿hpxAdminApp.controller('fBankBillOrderController', function (exportService, $rootScope, $interval, $scope, $stateParams, $filter, $state, API_URL, NgTableParams, fBankService, billService, constantsService, addressService, EXPORT_URL) {
    $scope.filter = {
        bill_status: '1',
    };
    //获取电票汇票瑕疵信息
    constantsService.queryConstantsType(19).then(function (data) {
        $scope.billFlawData = data;
    });
    //获取所有未审核或者已审核的票据资料信息
    $scope.tableParams = new NgTableParams({'sorting': {'publishing_time': 'desc'}}, {
        getData: function (params) {
            return fBankService.getBillOrderList(params, $scope.filter).then(function (data) {
                $scope.first = $scope.getFirst(params);
                console.log(data)
                return data;
            });
        }
    });
    //跳转到新页面，放大图片
    $scope.showFront = function () {
        window.open('index.html#/img?path=' + $scope.model.bill_front_photo_path);
    }
    $scope.showBack = function () {
        window.open('index.html#/img?path=' + $scope.model.bill_back_photo_path);
    }
    //刷新
    $scope.reflash = function () {
        $scope.tableParams.reload();
    }


    var timer = $interval($scope.reflash, 60 * 1000);
    $scope.$on(
        "$destroy",
        function (event) {
            $interval.cancel(timer);
        }
    );

    //设置瑕疵
    //$scope.initBillFlaw = function () {
    //    for (var i = 0; i < $scope.billFlawData.length; i++) {
    //        $scope.billFlawData[i].checked = false;
    //    }
    //    for (var i = 0; i < $scope.model.billFlaw.length; i++) {
    //        for (var j = 0; j < $scope.billFlawData.length; j++) {
    //            if ($scope.model.billFlaw[i] == $scope.billFlawData[j].code) {
    //                $scope.billFlawData[j].checked = true;
    //            }
    //        }
    //    }
    //}


    //点击审核/重新审核
    //$scope.check = function (item) {
    //    $scope.model = item;         //获取某条客户资料详细信息
    //    //弹出审核窗口
    //    $('#modal-check').modal('show');    
    //    $('.jqzoom').imagezoom();
    //};
    // 修改
    //$scope.updateCheck = function (item) {
    //    console.log(item)
    //    $scope.model = item;         //获取某条客户资料详细信息
    //    $('#modal-updateCheck').modal('show');
    //    $('.jqzoom').imagezoom();
    //}
    //$scope.saveUpload = function () {
    //    $scope.model.createTime = $filter('date')($scope.model.createTime, 'yyyy-MM-dd');
    //    $scope.model.discountedDate = $filter('date')($scope.model.discountedDate, 'yyyy-MM-dd');
    //    $scope.model.dueDate = $filter('date')($scope.model.dueDate, 'yyyy-MM-dd');
    //    $scope.model.billFlaw = [];
    //    for (var i = 0; i < $scope.billFlawData.length; i++) {
    //        if ($scope.billFlawData[i].checked) {
    //            $scope.model.billFlaw.push($scope.billFlawData[i].code);
    //        }
    //    }
    //    //审核票据产品，并推送审核结果给后台
    //    fBankService.fBankTrade($scope.model).then(function (data) {
    //        alert('修改成功！');
    //        $scope.tableParams.reload();
    //        $scope.checkForm.$setPristine();
    //        $('#modal-updateCheck').modal('hide');
    //    });
    //}
    //点击详细
    $scope.resd = function (item) {
        $scope.model = item;         //获取某条客户资料详细信息
        $('#modal-read').modal('show');
        $('.jqzoom').imagezoom();       //图片放大功能
    };
    //$scope.pass = function () {

    //    if (confirm('确认通过吗？')) {
    //        $scope.model.is_real = 1;
    //        save();
    //    }
    //};
    //$scope.reject = function () {
    //    if (!$scope.model.check_description || $scope.model.check_description.length == 0) {
    //        alert('请填写不通过原因！');
    //        return;
    //    }

    //    if (confirm('确认不通过吗？')) {
    //        $scope.model.is_real = 0;
    //        save();
    //    }
    //};

    //save = function () {
    //    $scope.model.createTime = $filter('date')($scope.model.createTime, 'yyyy-MM-dd');
    //    $scope.model.discountedDate = $filter('date')($scope.model.discountedDate, 'yyyy-MM-dd');
    //    $scope.model.dueDate = $filter('date')($scope.model.dueDate, 'yyyy-MM-dd');
    //    $scope.model.billFlaw = [];
    //    for (var i = 0; i < $scope.billFlawData.length; i++) {
    //        if ($scope.billFlawData[i].checked) {
    //            $scope.model.billFlaw.push($scope.billFlawData[i].code);
    //        }
    //    }
    //    //审核票据产品，并推送审核结果给后台
    //    fBankService.fBankTrade($scope.model).then(function (data) {
    //        $scope.tableParams.reload();
    //        //window.location.reload();
    //        $scope.checkForm.$setPristine();
    //        $('#modal-check').modal('hide');
    //    });
    //};
    //电票，当选中无瑕疵时，其他选项均为false；反之，选中其他选项时，无瑕疵选项为false
    $scope.billFlawChange = function (item) {
        if (item.code == 1500) {
            item.checked = true;
            for (var i = 1; i < $scope.billFlawData.length; i++) {
                $scope.billFlawData[i].checked = false;
            }
        }
        else {
            for (var i = 0; i < $scope.billFlawData.length; i++) {
                if (i == 0) {
                    $scope.billFlawData[i].checked = true;
                }
                else {
                    if ($scope.billFlawData[i].checked) {
                        $scope.billFlawData[0].checked = false;
                    }
                }
            }
        }
    }

});
